home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / PRIMES.BAT < prev    next >
DOS Batch File  |  1993-04-09  |  656b  |  24 lines

  1. @echo off
  2. REM Primes.bat    Print out prime numbers until a key is pressed or we run out
  3. REM               of memory or overflow
  4. cenvi %0.bat
  5. GOTO CENVI_EXIT
  6.  
  7. printf("Printing prime numbers until a key pressed (or failure):\n")
  8.  
  9. for ( Count = 0, Try = 2; !kbhit(); Try++ ) {
  10.    // check if this is divisible by any of the primes found so far
  11.    for ( i = 0; i < Count; i++ )
  12.       if !(Try % Prime[i])
  13.          break
  14.    if ( i == Count )
  15.       // this new prime number was found, and so add to the list and print it
  16.       printf("%d\t",Prime[Count++]=Try)
  17. }
  18. // flush the keyboard
  19. while( kbhit() ) getch()
  20.  
  21. printf("\n")
  22.  
  23. :CENVI_EXIT
  24.